﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace prDe_Tai
{
    public partial class frmMainForm : Form
    {
        public frmMainForm()
        {
            InitializeComponent();
        }
        string trangthailblloai = "";
        private void velabel(Label p)
        {
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            gp.AddEllipse(0, 0, p.Width, p.Height);
            Region myregion = new Region(gp);
            p.Region = myregion;
        }
        void hieuchinhlabel(Label lbl, OleDbDataReader r)
        {
            lbl.Text = r["chucnangphanmem"].ToString();
            lbl.Width = 149;
            lbl.Font = new Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            lbl.BorderStyle = BorderStyle.None;

            //velabel(lbl);
        }
        void hienthidautien()
        {
            flowLayoutPanel_FreeWare.Visible = false;
            flowLayoutPanel_ShareWare.Visible = false;
            flowLayoutPanel_Favourite.Visible = false;
            picFreeWare.BackgroundImage = picXuongSang.BackgroundImage;
            picShareWare.BackgroundImage = picXuongSang.BackgroundImage;
            picFavourite.BackgroundImage = picXuongSang.BackgroundImage;
            grbShareWare.Location = new Point(grbFreeWare.Location.X, grbFreeWare.Location.Y + grbFreeWare.Height);
            grbFavourite.Location = new Point(grbFavourite.Location.X, grbFreeWare.Location.Y + grbFreeWare.Height + grbShareWare.Height);
        }
        private void frmMainForm_Load(object sender, EventArgs e)
        {
            hienthidautien();
            flowLayoutPanel_FreeWare.Size = new Size(159, 150);
            flowLayoutPanel_ShareWare.Size = new Size(159, 150);
            flowLayoutPanel_Favourite.Size = new Size(159, 150);
            //    OleDbConnection con = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=QuanLyPhanMem.mdb");
            //    OleDbCommand com = new OleDbCommand();
            //    com.Connection = con;
            //    com.CommandType = CommandType.Text;
            //    com.CommandText = "select distinct chucnangphanmem from DanhSachPhanMem order by chucnangphanmem";
            //    con.Open();
            //   OleDbDataReader r = com.ExecuteReader();
            //    while (r.Read())
            //    {
            //        LinkLabel lbl = new LinkLabel();
            //        hieuchinhlabel(lbl,r);
            //        lbl.Click += label1_Click;
            //        flowLayoutPanel_FreeWare.Controls.Add(lbl);
            //        lbl.Location = new Point(100,100);
            //        ///////////////////////////////////////////
            //        LinkLabel lbl1 = new LinkLabel();
            //        hieuchinhlabel(lbl1,r);
            //        lbl1.Click += label1_Click;
            //        flowLayoutPanel_ShareWare.Controls.Add(lbl1);
            //        lbl1.Location = new Point(100,100);
            //        ///////////////////////////////////////////
            //        LinkLabel lbl2 = new LinkLabel();
            //        hieuchinhlabel(lbl2, r);
            //        lbl2.Click += label1_Click;
            //        flowLayoutPanel_Favourite.Controls.Add(lbl2);
            //        lbl2.Location = new Point(100,100);
            //    }
            //    r.Close();
            //    con.Close();

        }
        void vitrisharewaremo()
        {
            vitrifreewaredong();
            vitrifavouritedong();
            picShareWare.BackgroundImage = picXuongToi.BackgroundImage;
            grbShareWare.Location = new Point(grbShareWare.Location.X, grbFreeWare.Location.Y + grbFreeWare.Height);
            flowLayoutPanel_ShareWare.Location = new Point(flowLayoutPanel_ShareWare.Location.X, grbFreeWare.Location.Y + grbFreeWare.Height + grbShareWare.Height);
            flowLayoutPanel_ShareWare.Visible = true;
            grbFavourite.Location = new Point(grbFavourite.Location.X, grbFreeWare.Location.Y + grbFreeWare.Height + grbShareWare.Height + flowLayoutPanel_ShareWare.Height);
        }
        void vitrisharewaredong()
        {
            picShareWare.BackgroundImage = picXuongSang.BackgroundImage;
            grbShareWare.Location = new Point(grbShareWare.Location.X, grbFreeWare.Location.Y + grbFreeWare.Height + flowLayoutPanel_FreeWare.Height);
            flowLayoutPanel_ShareWare.Visible = false;
        }
        void vitrifreewaremo()
        {
            vitrisharewaredong();
            vitrifavouritedong();
            picFreeWare.BackgroundImage = picXuongToi.BackgroundImage;
            flowLayoutPanel_FreeWare.Visible = true;
            grbFavourite.Location = new Point(grbFavourite.Location.X, grbFreeWare.Location.Y + grbFreeWare.Height + flowLayoutPanel_FreeWare.Height + grbShareWare.Height);
        }
        void vitrifreewaredong()
        {
            flowLayoutPanel_FreeWare.Visible = false;
            picFreeWare.BackgroundImage = picXuongSang.BackgroundImage;
        }
        void vitrifavouritemo()
        {
            vitrifreewaredong();
            vitrisharewaredong();
            picShareWare.BackgroundImage = picXuongSang.BackgroundImage;
            flowLayoutPanel_ShareWare.Visible = false;
            grbShareWare.Location = new Point(grbShareWare.Location.X, grbFreeWare.Location.Y + grbFreeWare.Height);
            picFavourite.BackgroundImage = picXuongToi.BackgroundImage;
            grbFavourite.Location = new Point(grbFavourite.Location.X, grbFreeWare.Location.Y + grbFreeWare.Height + grbShareWare.Height);
            flowLayoutPanel_Favourite.Location = new Point(flowLayoutPanel_Favourite.Location.X, grbFreeWare.Location.Y + grbFreeWare.Height + grbShareWare.Height + grbFavourite.Height);
            flowLayoutPanel_Favourite.Visible = true;

        }
        void vitrifavouritedong()
        {

            picFavourite.BackgroundImage = picXuongSang.BackgroundImage;
            flowLayoutPanel_Favourite.Visible = false;
        }
        int dem, dem1, dem2;
        private void lblFreeWare_Click(object sender, EventArgs e)
        {
            Label lbl = (Label)sender;
            if (lbl.Text == "Miễn Phí")
            {
                dem++;
                dem1 = 0;
                dem2 = 0;
                vitrifreewaremo();
                trangthailblloai = lbl.Text.ToLower();
                if (dem == 2)
                {
                    hienthidautien();
                    dem = 0;
                }
            }
            else if (lbl.Text == "Có Phí")
            {
                dem = 0;
                dem1++;
                dem2 = 0;
                vitrisharewaremo();
                trangthailblloai = lbl.Text.ToLower();
                if (dem1 == 2)
                {
                    hienthidautien();
                    dem1 = 0;
                }
            }
            else
            {
                dem = 0;
                dem1 = 0;
                dem2++;
                vitrifavouritemo();
                trangthailblloai = lbl.Text.ToLower();
                if (dem2 == 2)
                {
                    vitrifavouritedong();
                    dem2 = 0;
                }
            }
        }
        private void label1_Click(object sender, EventArgs e)
        {

            DataSet ds = new DataSet();
            Label lbl = (Label)sender;
            OleDbConnection con = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=QuanLyPhanMem.mdb");
            OleDbCommand com = new OleDbCommand();
            com.Connection = con;
            com.CommandType = CommandType.Text;
            com.CommandText = "select * from DanhSachPhanMem where chucnangphanmem=@chucnangphanmem and loaiphanmem=@loaiphanmem";
            //Khoi tao 2 tham so
            OleDbParameter pa = new OleDbParameter("@chucnangphanmem", OleDbType.BSTR);
            pa.Value = lbl.Text;
            OleDbParameter pa1 = new OleDbParameter("@loaiphanmem", OleDbType.BSTR);
            pa1.Value = trangthailblloai;
            //add them 2 tham so vao command
            com.Parameters.Add(pa);
            com.Parameters.Add(pa1);
            con.Open();
            OleDbDataReader r = com.ExecuteReader();
            while (r.Read())
            {
                ListViewItem li = lvwHienThi.Items.Add(r["tenphanmem"].ToString());
                li.ImageIndex = 0;
            }
            r.Close();
            con.Close();
        }

        void lbl1_Click(object sender, EventArgs e)
        {
            Label lbl = (Label)sender;
            OleDbConnection con = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=QuanLyPhanMem.mdb");
            OleDbCommand com = new OleDbCommand();
            com.Connection = con;
            com.CommandType = CommandType.Text;
            com.CommandText = "select tenphanmem,loaiphanmem,chucnangphanmem,diachidownload from DanhSachPhanMem where tenphanmem=?";
            OleDbParameter pa = new OleDbParameter("?", OleDbType.BSTR);
            pa.Value = lbl.Text;
            com.Parameters.Add(pa);
            con.Open();
            OleDbDataReader r = com.ExecuteReader();
            while (r.Read())
            {
                lblTenPhanMem.Text = r["tenphanmem"].ToString();
                lblLoaiPhanMem.Text = r["loaiphanmem"].ToString();
                lblChucNangPhanMem.Text = r["chucnangphanmem"].ToString();
                lblDiaChiDownload.Text = r["diachidownload"].ToString();

            } r.Close();
            con.Close();
        }

        void pic_MouseClick(object sender, MouseEventArgs e)
        {
            PictureBox pic = (PictureBox)sender;
            OleDbConnection con = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=QuanLyPhanMem.mdb");
            OleDbCommand com = new OleDbCommand();
            com.Connection = con;
            com.CommandType = CommandType.Text;
            com.CommandText = "select tenphanmem,loaiphanmem,chucnangphanmem,diachidownload from DanhSachPhanMem where tenphanmem=?";
            OleDbParameter pa = new OleDbParameter("?", OleDbType.BSTR);
            pa.Value = pic.Tag;
            com.Parameters.Add(pa);
            con.Open();
            OleDbDataReader r = com.ExecuteReader();
            while (r.Read())
            {
                lblTenPhanMem.Text = r["tenphanmem"].ToString();
                lblLoaiPhanMem.Text = r["loaiphanmem"].ToString();
                lblChucNangPhanMem.Text = r["chucnangphanmem"].ToString();
                lblDiaChiDownload.Text = r["diachidownload"].ToString();

            } r.Close();
            con.Close();
        }
        //Giới thiệu về chủ đề 
        private void linkLabel1_MouseHover(object sender, EventArgs e)
        {
            LinkLabel lbl = (LinkLabel)sender;
            if (lbl.Text == "System")
                lblGioiThieu.Text = "Các chương trình sửa chữa , bảo trì hệ thống";
            if (lbl.Text == "Virus-Security")
                lblGioiThieu.Text = "Các chương trình phát hiện và diệt virus";
            if (lbl.Text == "Graphics")
                lblGioiThieu.Text = "Các chương trình xử lý về đồ họa";
            if (lbl.Text == "Multimedias")
                lblGioiThieu.Text = "Các chương trình xử lý đa phương tiện";
            if (lbl.Text == "Style-Themes")
                lblGioiThieu.Text = "Các chương trình tạo giao diện";
            if (lbl.Text == "Utilities")
                lblGioiThieu.Text = "Các chương trình đa ứng dụng , đa chức năng";           
        }

        private void linkLabel1_Click(object sender, EventArgs e)
        {
            lvwHienThi.Items.Clear();
            DataSet ds = new DataSet();
            Label lbl = (Label)sender;
            OleDbConnection con = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=QuanLyPhanMem.mdb");
            OleDbCommand com = new OleDbCommand();
            com.Connection = con;
            com.CommandType = CommandType.Text;
            com.CommandText = "select * from DanhSachPhanMem where chude=@chude and loaiphanmem=@loaiphanmem";
            //Khoi tao 2 tham so
            OleDbParameter pa = new OleDbParameter("@chude", OleDbType.BSTR);
            pa.Value = lbl.Text;
            OleDbParameter pa1 = new OleDbParameter("@loaiphanmem", OleDbType.BSTR);
            pa1.Value = trangthailblloai;
            //add them 2 tham so vao command
            com.Parameters.Add(pa);
            com.Parameters.Add(pa1);
            con.Open();
            OleDbDataReader r = com.ExecuteReader();
            while (r.Read())
            {
                ListViewItem li = lvwHienThi.Items.Add(r["tenphanmem"].ToString());
                li.ImageIndex = 0;
            }
            r.Close();
            con.Close();
        }

        private void lvwHienThi_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvwHienThi.SelectedItems.Count > 0)
            {
                string tenphanmem = lvwHienThi.SelectedItems[0].SubItems[0].Text;
                
                OleDbConnection con = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=QuanLyPhanMem.mdb");
                OleDbCommand com = new OleDbCommand();
                com.Connection = con;
                com.CommandType = CommandType.Text;
                com.CommandText = "select tenphanmem,loaiphanmem,chucnang,diachidownload from DanhSachPhanMem where tenphanmem=?";
                OleDbParameter pa = new OleDbParameter("?", OleDbType.BSTR);
                pa.Value = tenphanmem;
                com.Parameters.Add(pa);
                con.Open();
                OleDbDataReader r = com.ExecuteReader();
                while (r.Read())
                {
                    lblTenPhanMem.Text = r["tenphanmem"].ToString();
                    lblLoaiPhanMem.Text = r["loaiphanmem"].ToString();
                    lblChucNangPhanMem.Text = r["chucnang"].ToString();
                    lblDiaChiDownload.Text = r["diachidownload"].ToString();

                } r.Close();
                con.Close();
            }

        }

        private void linkLabel7_MouseLeave(object sender, EventArgs e)
        {
            lblGioiThieu.Text = "";
        }
        string chuoi = "Trường Đại Học Công Nghiệp Thành Phố Hồ Chí Minh "+Environment.NewLine+"Đề tài chương trình quản lý phần mềm , tiện ích"+Environment.NewLine+"Các thành viên :"+Environment.NewLine+"1.Trần Lê Bảo Thanh"+Environment.NewLine+"2.Nguyển Hoàng Tú"+Environment.NewLine+"3.Trần Minh Đạo"+Environment.NewLine+"4.Cao Trí Thức";
        int i =11,k=11;
        private void timer1_Tick(object sender, EventArgs e)
        {
            lblTacGia.Text = "";
            for (int j = 1; j <= i; j++) 
            {
                lblTacGia.Text += Environment.NewLine; 
            } 
            lblTacGia.Text = lblTacGia.Text + chuoi;
            for (int l = 1; l <= k; l++)
            {
                lblTacGia.Text += Environment.NewLine;
            } 
            i -= 1;
            k--;
            if (i == -1) 
                i = 11;
            if (k == -1)
                k = 11;
        }

       

        
    }
}



        

        

       

        

        

        
